package Adapters;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.dotatrivia.R;

import entities.Hero;

public class HeroAdapter extends BaseAdapter {

	 //Lista de heroes!
		private List<Hero> heroes;
		private LayoutInflater mInflater;
	//	private ViewHolder holder;
		private Context mContext;
		private static int jumpPos = 0;
	 
	 
		static class ViewHolder{
			private ImageView img;
			private TextView heroName;			
		}
	 
	 
		public HeroAdapter(Context context, List<Hero> heroes) {
			mInflater = LayoutInflater.from(context);
			this.heroes = heroes;
			mContext = context;
		}
	 
		@Override
		public int getCount() {
			return heroes.size();
		}
	 
		@Override
		public Hero getItem(int index) {
			return heroes.get(index);
		}
	 
		@Override
		public long getItemId(int index) {
			//return heroes(index).getImgRes();
			return index;
		}
	 
		@Override
		public View getView(int posicao, View convertView, ViewGroup arg2) {
	
			ViewHolder holder;
			if (convertView == null) {
				convertView = mInflater.inflate(R.layout.activity_main, null);
				holder = new ViewHolder();  
	            holder.img = (ImageView) convertView.findViewById(R.id.img);
	            holder.heroName = (TextView) convertView.findViewById(R.id.nome);
	            convertView.setTag(holder);

	 
		
	 
			} else {
				holder = (ViewHolder) convertView.getTag();
			}
	 
			while(heroes.get(posicao+jumpPos)== null){
				jumpPos++;
			}
			Hero h = heroes.get(posicao+jumpPos);
	 
			holder.heroName.setText(h.getLocalized_name());
			holder.img.setImageResource(h.getImgRes(mContext));
	 
			return convertView;
		}
	 

}
